/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D3897C2C-AB36-47A0-8212-7477C7C7DF7B",variableType:4}
 */
var fEdad = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"880BE458-693B-4371-B2EE-7754AEF172F4",variableType:4}
 */
var fHospital = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"F5731731-E19B-476D-B3C5-908316E8387C",variableType:4}
 */
var f_paciente = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"30A25B91-81CB-4B60-AADE-DB5C1427C2C9"}
 */
var f_codigo = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"602C8436-4E3E-41B6-846D-E006BE0F8CEA"}
 * @AllowToRunInFind
 */
function buscar(event) {
	/** @type {String}*/
	var $where = ''
	var $args = new Array()
	
	if (f_codigo != null)
	{
		$where += ' and upper(md.cod_interno) like upper(?) '
		$args.push('%' + f_codigo + '%')
	}
	if (f_paciente != null)
	{
		$where += ' and m.paciente_id = ? '
		$args.push(f_paciente)
	}
	if (fHospital != null)
	{
		$where += ' and md.hospital_id = ? '
		$args.push(fHospital)
	}
	if (fEdad != null)
	{
		$where += ' and date_part(\'year\',m.fecha) - date_part(\'year\',p.fecha_nacimiento) > ? '
		$args.push(fEdad)
	}
	if ($where != '')
	{
		$where = $where.substring(4,$where.length)
	
		var $query = 'SELECT muestra_destino_id FROM muestra_destino "md" '+
						'JOIN muestras "m" ON m.muestra_id = md.muestra_id '+
						'JOIN pacientes "p" ON p.paciente_id = m.paciente_id '+
						'WHERE '+$where
		var $ds = databaseManager.getDataSetByQuery('cepario',$query,$args,-1)
		if ($ds.getMaxRowIndex() == 0)
		{
			globals.DIALOGS.showInfoDialog('Aviso','No se encontraron muestras destino con esas condiciones','OK')
		}
		controller.loadRecords($ds)
	}
	else
	{
		controller.loadAllRecords()
		controller.sort('fecha desc')
	}
	return true;
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"EE1D6951-AE3D-42E5-9749-5F0830CD60AB"}
 */
function anular(event) 
{
	f_codigo 	= null;
	f_paciente 	= null;
	fHospital 	= null
	fEdad 		= null
}

/**
 * @properties={typeid:24,uuid:"171D001C-3087-4266-A927-B17BEBDDEA14"}
 */
function iraDtl()
{
	globals.mostrarForm('muestra_destino_dtl')
}
